package com.dhkj.web.idf;

import android.content.Context;
import android.util.Base64;

import com.dhkj.web.idf.model.ActiveWraper;
import com.dhkj.web.idf.model.IDFWraper;
import com.dhkj.web.idf.model.QueryWraper;
import com.dhkj.web.utils.MyObserverNo;
import com.dhkj.web.utils.RxHelper;

import org.json.JSONObject;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class IdfRequestUtils {

    public static void registrationQuery(Context context, MyObserverNo<ActiveWraper> observer) {
        RetrofitIdfCenterUtils.getApiUrl().registrationQuery()
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    public static void bigRecognition(Context context, int library_id, byte[] data, MyObserverNo<IDFWraper> observer) {
        org.json.JSONObject jsonObject = new org.json.JSONObject();
        try {
            jsonObject.put("library_id", library_id);
            jsonObject.put("image_base64", "data:image/jpg;base64," + Base64.encodeToString(data, Base64.DEFAULT));
            System.out.println("jsonObject:" + jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString().getBytes());
        RetrofitIdfCenterUtils.getApiUrl().bigRecognition(requestBody)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    public static void query(Context context, MyObserverNo<QueryWraper> observer) {
        JSONObject jsonObject = new JSONObject();
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString().getBytes());
        RetrofitIdfCenterUtils.getApiUrl().query(requestBody)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

}
